apiready = function(){
api.addEventListener({
    name:'viewdisappear'
}, function(ret, err){        
   api.closeWin();
});
if(api.connectionType=='none'){
			error();
			  var reloading = $api.byId('reloading');
			  $api.addEvt(reloading, 'click', function(){
			  	api.closeToWin({
	                  name: 'root'
                  });
			  });
			  	return;
  	
  			}
headerstatus()
	var name = api.pageParam.type;
	var id = api.pageParam.id;
	var url =api.pageParam.url;
	var title = api.pageParam.title;
	var remark = api.pageParam.remark;
	if(url){
		
		
		openUrlFrame(url,name,remark);	
		$api.html($api.byId('h_name'),''+title);
		
		//showHeader(name);
	}else{
		showHeader(name);
    	var uid =api.pageParam.uid;
    	
    	openDetailframe(name,id,uid);
	}
	
    
    /*if(name=='pastLottery'){
    	$("#go").show();
    }*/
}
   //toggle header
function showHeader(type){
	
    if(!type){return;}
    var header = $api.dom('#header .active');
    
    $api.removeCls(header,'active');
    var thisHeader = $api.dom('#header .'+type);
    $api.addCls(thisHeader,'active');
} 
function openDetailframe(name,id,uid){
	
	var width = api.winWidth;
	var header = $api.byId('header');
	var headerPos = $api.offset(header);

	var height = api.winHeight - headerPos.h;
	api.closeFrame({
        name:'cart'
    })
   
 
	api.openFrame({
		name:name,
		url:'./'+name+'.html',
		rect:{
			 x: 0,
             y: headerPos.h,
             w: width,
             h: height
		},
		customRefreshHeader: 'UIPullRefresh',
		pageParam: {shopId: id,uid: uid},
		reload:true

	});
}
//打开url
function openUrlFrame(url,name,remark){
	api.closeFrame({
        name:'pastLottery'
    })
	var width = api.winWidth;
	var header = $api.byId('header');
	var headerPos = $api.offset(header);
	//alert(headerPos.h)

	var height = api.winHeight - headerPos.h;

	api.openFrame({
		name:'jingpay',
		url:''+url,
		rect:{
			 x: 0,
             y:headerPos.h,
             w: width,
             h: height
		},
		
		customRefreshHeader: 'UIPullRefresh',
		
		reload:true
		

	});
	if(remark=='wx'){
	
	
		api.openFrame({
		name:'wxpay',
		url:'./test.html',
		rect:{
			 x: 0,
             y:headerPos.h,
             w: width,
             h: height
		},
		
		customRefreshHeader: 'UIPullRefresh',
		
		reload:true,
		

	});
	}
	
}

